package com.woniuxy.microorderserver.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.microcommonserver.bean.order_caize.OrderInfo;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import com.woniuxy.microcommonserver.pageHelper.TableResult;
import com.woniuxy.microcommonserver.res.ResultMsg;
import com.woniuxy.microorderserver.service.IOrderService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private IOrderService OrderServiceimpl;

    /**
     * 根据用户id查询用户所有的订单
     * @param request
     * @param
     * @return
     */
    @RequestMapping(value = "/all",produces = {"application/json;charset=utf-8"})
    public TableResult<OrderInfo> findOrderAllBySearch(PageRequest request, OrderInfo orderInfo){
        PageInfo<OrderInfo> pageInfo = OrderServiceimpl.findOrderAllBySearch(request,orderInfo);

        return new TableResult(pageInfo.getTotal(),pageInfo.getList());
    }


    /**
     * 根据订单id删除订单
     * @param id
     * @return
     */
    @RequestMapping(value = "/delOrder",produces = {"application/json;charset=utf-8"})
    public ResultMsg delOrder(Long id){
        int i = OrderServiceimpl.delOrder(id);
        if(i == 1){
            return ResultMsg.builder().code(200).msg("删除成功！").build();
        }else {
            return ResultMsg.builder().code(1000).msg("您出错啦！").build();
        }
    }
    /**
     * 根据订单编号查看订单详情。订单信息。收货人信息
     */
    @RequestMapping(value = "/detail",produces = {"application/json;charset=utf-8"})
    public OrderInfo findOrderByOrderNum(Long orderNum){
        OrderInfo orderByOrderNum = OrderServiceimpl.findOrderByOrderNum(orderNum);
        return orderByOrderNum;
    }

}
